<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
    
    </style>
</head>


<body>
    <div id="app">

        <ul>
            <li v-for="(item,index) in fruit">{{item.name}}--{{item.num}}</li>
        </ul>
        <div>总数： {{sumCount}}</div>
    </div>


    <script src="https://cdn.jsdelivr.net/npm/vue@2.7.16/dist/vue.js"></script>
    <script>
        // Vue 实例 在全局环境，就有了Vue构造函数
        const app = new Vue({
            // 通过el 配置选择器
            el: '#app',
            data: {
               fruit:[
                {id:1,name:"篮球",num:2},
                {id:2,name:"羽毛球",num:5},
                {id:3,name:"足球",num:9},
                {id:4,name:"铅球",num:1},
                
               ]
            },
            computed:{
                sumCount(){
                    let total = this.fruit.reduce((prev,item) => prev+item.num,0);
                    return total;
                }
            }
        });
    </script>
</body>

</html>